<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地图导航</title>
    <style>
        * {
          margin: 0;
          padding: 0;
        }
        #container {
          width: 100%;
          height: 100vh;
          background-color: pink;
        }
    </style>
</head>
<body>
<div id="container"></div>
</body>
</html>

<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "44fc71d7d4ea7fe3ec2694bfa5016185",
    };
</script>
<script
        type="text/javascript"
        src="https://webapi.amap.com/maps?v=2.0&key=73110cc8e0cbf701e4a157be0d7d6364"
></script>
<script type="text/javascript">
    //地图初始化应该在地图容器 <div> 已经添加到 DOM 树之后
    var map = new AMap.Map("container", {
      zoom: 18,
      center:[116, 40]
    });

    window.onload=function(){
        window.swift.setCurrentLocation() // 调用鸿蒙端方法定位
    }

    function setLocation(lon, lat){
        map.setZoomAndCenter(18,[lon,lat])

        // 设置当前位置
        const content = `<div class="custom-content-marker"><img src="https://a.amap.com/jsapi_demos/static/demo-center/icons/dir-via-marker.png"></div>`;
        const marker = new AMap.Marker({
          content: content,
          position: [lon, lat],
          offset: new AMap.Pixel(-13, -30),
        });
        map.add(marker);
        //搜索最近的几个地点
        map.plugin(['AMap.PlaceSearch'], function() {
            var PlaceSearchOptions = {
                pageSize: 4,
                pageIndex: 1,
                map: map,
                extensions: "base"
            };
            var MSearch = new AMap.PlaceSearch(PlaceSearchOptions);
            AMap.Event.addListener(MSearch, "complete", (result)=>{
                window.swift.receiveData(JSON.stringify(result?.poiList?.pois||[]))
            });
            MSearch.searchNearBy("街道", new AMap.LngLat(lon,lat));
        });
    }
</script>